package com.phonebook.entity;

import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 页面响应entity
 * 默认 0 成功 500 失败
 *
 * @author java1234_小锋
 * @date 2019-08-13 上午 10:00
 */
@Data
@ApiModel(value = "页面响应entity")
public class ResponseResult extends HashMap<String, Object> {

    @Override
    public ResponseResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public static ResponseResult error() {
        ResponseResult r = new ResponseResult();
        r.put("code", 500);
        r.put("msg", "未知异常，请联系管理员");
        return r;
    }

    public static ResponseResult error(String msg) {
        ResponseResult r = new ResponseResult();
        r.put("code", 500);
        r.put("msg", msg);
        return r;
    }

    public static ResponseResult error(Integer code,String msg) {
        ResponseResult r = new ResponseResult();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static ResponseResult success() {
        ResponseResult r = new ResponseResult();
        r.put("msg", "成功");
        r.put("code", 200);
        return r;
    }

    public static ResponseResult success(String msg) {
        ResponseResult r = new ResponseResult();
        r.put("code", 200);
        r.put("msg", msg);
        return r;
    }

    public static ResponseResult success(List<Map<String, Object>> data) {
        ResponseResult r = new ResponseResult();
        r.put("code", 200);
        r.put("msg", "成功");
        r.put("data", data);
        return r;
    }

    public static ResponseResult success(Map<String, Object> data) {
        ResponseResult r = new ResponseResult();
        r.put("code", 200);
        r.put("msg", "成功");
        r.put("data", data);
        return r;
    }

    public static ResponseResult success(String msg, List<Map<String, Object>> data) {
        ResponseResult r = new ResponseResult();
        r.put("code", 200);
        r.put("msg", msg);
        r.put("data", data);
        return r;
    }

    public static ResponseResult success(String msg, Map<String, Object> data) {
        ResponseResult r = new ResponseResult();
        r.put("code", 200);
        r.put("msg", msg);
        r.put("data", data);
        return r;
    }

}
